<?php

namespace study;
use \Exception;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/11
 * Time: 15:17
 */
class YflAutoLoader
{

    public static function load($className)
    {
        $pathClassName = __DIR__ . '\\classOrg\\' . $className . '.php';
        if (file_exists($pathClassName) === false) {
            throw new Exception("No such file as $pathClassName");
        }else{
            require_once $pathClassName;
        }
        if (class_exists($className, false) == false) {
            throw new Exception("No such class as $pathClassName");
        }

    }

    public static function register()
    {
        $functionArr = spl_autoload_functions();
        if (!empty($functionArr)) {
            //        return $functionArr;
            foreach ($functionArr as $function) {
                spl_autoload_unregister($function);
            }
            $functionArr = array_merge(array(array('\\study\\YflAutoLoader', 'Load')), $functionArr);
//        return $functionArr;
            foreach ($functionArr as $function) {
                $res = spl_autoload_register($function);

            }
        } else {
            $res = spl_autoload_register(array('\\study\\YflAutoLoader', 'Load'));
        }
        return $res;
    }
}

YflAutoLoader::register();